package com.the_ring.behavior.media;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author: t22306139
 * @date: 2023/12/1  15:25
 */
public class HouseAgent implements Mediator{

    private List<HouseOwner> houseOwners = new ArrayList<>();
    private List<HouseTenant> houseTenants = new ArrayList<>();

    /**
     * 中介发布房屋信息，就向所有的租客传递房源信息
     * @param message
     */
    @Override
    public void publicHouse(String message) {
        if (!this.houseTenants.isEmpty()) {
            for (HouseTenant tenant : this.houseTenants) {
                tenant.contact(message);
            }
        }
    }

    /**
     * 当有人需要房子时，中介就向所有的房东传递信息
     * @param message
     */
    @Override
    public void needHouse(String message) {
        if (!this.houseOwners.isEmpty()) {
            for (HouseOwner owner : this.houseOwners) {
                owner.contact(message);
            }
        }
    }

    public void setHouseOwners(HouseOwner... houseOwners) {
        this.houseOwners.addAll(Arrays.asList(houseOwners));
    }

    public void setHouseTenants(HouseTenant... houseTenants) {
        this.houseTenants.addAll(Arrays.asList(houseTenants));
    }
}
